package factory;

import PO.CoursePO;
import PO.FramePO;
import data.course;
import data.mainFrame;
import data.subFrame;
import dataBase.userBaseConnector;

public class CourseFactory {

	public course courseMaker(String[] info){
		return new course(info[0],info[1],info[2],info[3],info[4],info[5],info[6],info[7],info[8],info[9],
					info[10],info[11],info[12],info[13],info[14]);
	}
	
	public course courseMaker(CoursePO cp){
		return new course(cp.getCourseNO(),cp.getCourseName(),cp.getCourseType()
				,String.valueOf(cp.getCredit()),cp.getTime(),cp.getClassroom(),cp.getDepart()
				,null,cp.getTeacher(),cp.getDescribtion()
				,cp.getComment()[0]+","+cp.getComment()[1],null,String.valueOf(cp.getGrade()),
				String.valueOf(cp.getMaxStudent()),null);
	}
	
	public CoursePO coursePOMaker(course c){
		String[] comment = c.getComment().split(",");
		
		CoursePO cp = new CoursePO(c.getdepart(),c.getID(),c.getName(),c.getType(),c.getCredit()
				,Integer.valueOf(c.getGrade()),c.getTime(),c.getClassroom(),c.getTeacher(),
				Integer.valueOf(c.getMaxStudent()),c.getDescribtion());
		cp.setComment(new double[]{Double.parseDouble(comment[0]),Double.parseDouble(comment[1])});
		return cp;
	}
	
	public mainFrame mainFrameMake(FramePO fpo){
		return new mainFrame(fpo.getModule(),fpo.getCategory(),fpo.getSN(),fpo.getCourseType()
				,fpo.getCredit()[0],fpo.getTime());
	}
	
	public subFrame[] subFrameMake(FramePO fpo){
		int count = 0;
		for(int j = 0;j<fpo.getCourseName().length;j++){
			if(fpo.getCourseName()[j]!=null)
				if(!fpo.getCourseName()[j].equals(""))
					count++;
		}
		subFrame[] s = new subFrame[count];
		for(int i = 0;i<count;i++){
			s[i] = new subFrame(fpo.getCourseName()[i],fpo.getSN(),fpo.getCredit()[i]);
		}
		return s;
	}
	
	public mainFrame mainFrameMaker(String[] info){
		return new mainFrame(info[0],info[1],info[2],info[3],info[4],info[5]);
	}
	
	public subFrame subFrameMaker(String info[]){
		return new subFrame(info[0],info[1],info[2]);
	}
	
	public FramePO FramePOMake(mainFrame mf,subFrame[] sb){
		String[] courseName = new String[sb.length];
		String[] credit = new String[sb.length];
		if(sb.length==0){
			credit = new String[]{mf.getCredit()};
			courseName = new String[]{};
		}
			
		else{
			for(int i = 0;i<sb.length;i++){
				courseName[i] = sb[i].getCoursename();
				credit[i] = sb[i].getCredit();
			}
		}
		
		return new FramePO(mf.getModule(),mf.getType(),mf.getSerialNumber(),mf.getCategory()
				,courseName,credit,mf.getTime());
	}
}
